<!doctype html>
<html lang="en" data-bs-theme="auto">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="">
  <title>分类管理</title>

  <link href="/assets/dist/css/bootstrap.min.css" rel="stylesheet">
  <link rel="stylesheet" href="/assets/icons/font/bootstrap-icons.css">
  <link rel="stylesheet" href="/libs/tree/select-tree.css">
  
  <link href="/css/dashboard.css" rel="stylesheet">
  <script src="/js/jquery.min.js"></script>
  <script src="/libs/tree/select-tree.js"></script>
</head>

<body>

  <div class="container">
  <h5>分类管理</h5>
  <hr>
  <div class="row p-3">
      <div class="col-10">
        <table class="table table-bordered">
          <thead>
            <tr>
              <th scope="col">#</th>
              <th scope="col">分类</th>
              <th scope="col">名称</th>
              <th scope="col">Logo</th>
              <th scope="col">排序</th>
              <th scope="col">编辑</th>
            </tr>
          </thead>
          <tbody>
            <%c for(auto &a:obj["list"].as_array()){ %>
              <tr id="topicid_<%c echo<<a["id"].to_string(); %>">
                <td>
                  <%c echo<<a["id"].to_string(); %>
                </td>
                <td>
                  <%c echo<<a["cname"].as_string(); %>
                </td>
                <td>
                  <%c echo<<a["name"].as_string(); %>
                </td>
                
                <td>
                  <img src="<%c echo<<a["logo"].as_string(); %>" width="60" height="60" />  <a href="<%c echo<<a["logo"].as_string(); %>" target=_blank>View</a>
                </td>
                <td>
                  <input type="text" class="form-inline topicsort col-md-2" id="title_<%c echo<<a["id"].to_string(); %>" name="title_<%c echo<<a["id"].to_string(); %>" value="<%c echo<<a["sortid"].to_string(); %>" onchange="updatebrandsort(<%c echo<<a["id"].to_string(); %>,this.value)">
                </td>
                <td>
                  <a href="/admin/marbrand?id=<%c echo<<a["id"].to_string(); %>">编辑</a>｜
                  <a href="/admin/deletebrand?id=<%c echo<<a["id"].to_string(); %>" onclick="return confirm('确定删除吗？')">删除</a>
                </td>
              </tr>
              <%c } %>
          </tbody>

        </table>
      </div>
    </div>


    <form class="g-3 mt-1" id="form" method="post" action="/admin/brandaddpost" >
        <div class="row p-3">
      <div class="col-md-6">
        <label for="topicid" class="form-label">栏目</label>
        <select class="form-select" id="topicid" name="topicid">
        <option value="0">无分类</option>
        <%c for(auto &a:obj["topiclist"].as_array()){ %>
        <option value="<%c echo<<a["id"].to_string(); %>" <%c if(obj["topicid"].to_int()==a["id"].to_int()){ %>selected<%c } %>><%c echo<<a["name"].to_string(); %></option>
        <%c } %>
        </select>
      </div>
      <div class="col-md-6">
        <label for="topicname" class="form-label">名称</label>
        <input type="text" class="form-control" id="topicname" name="topicname" value="<% echo<<obj["info"]["title"].to_string(); %>">
      </div>
      
      </div>
      
      <div class="row p-3">
            <label for="icoimg" class="col-md-2 col-form-label text-sm-end">Logo</label>
            <div class="col-md-6">
              <div class="input-group mb-3">
              <input type="text" class="form-control" id="icoimg" name="icoimg" value="<% echo<<obj["info"]["logo"].to_string(); %>" placeholder="品牌标志">
              <input class="form-control" type="file" style="width:100px" id="relate-icoimg" accept=".png,.jpg,.jpeg">
              </div>
            </div>
            <div class="col-md-4">
              <div class="progress" id="progress-bar-show" style="display:none" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
                  <div class="progress-bar" id="progress-bar" style="width: 0%">0</div>
                </div>
              <div id="progress-bar-result"></div>  
            </div>
      </div> 

                <div class="row p-3">
            <label for="editor" class="col-md-2 col-form-label text-sm-end">品牌介绍</label>
            <div class="col-md-10">
              <textarea class="form-control" id="editor" rows="4" name="content"
                placeholder=""><% echo<<obj["info"]["detailcontent"].to_string(); %></textarea>
            </div>
          </div>

          <div class="row p-3">
            <label for="introduce" class="col-md-2 col-form-label text-sm-end">自定义内容（首页）</label>
            <div class="col-md-10">
              <textarea class="form-control" id="introduce" rows="4" name="introduce"
                placeholder=""><% echo<<obj["info"]["introduce"].to_string(); %></textarea>
            </div>
          </div>
          
      <div class="col-12">
        <input type="hidden" id="brandid" name="brandid" value="<% echo<<obj["info"]["brandid"].to_string(); %>" />
        <button type="submit" class="btn btn-primary">提交</button>
      </div>
    </form>

  </div>
  
<div class="modal fade" id="myfiletobigModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h1 class="modal-title fs-5" id="staticBackdropLabel">提示</h1>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
         文件太大了，请传4M以下的文件！
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
         
      </div>
    </div>
  </div>
</div>  

<div class="modal fade" id="myfilesuccessModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="myfilesuccess" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h1 class="modal-title fs-5" id="myfilesuccess">提示</h1>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
         上传成功！
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">确定</button>
         
      </div>
    </div>
  </div>
</div>
  
  <script src="/assets/dist/js/bootstrap.bundle.min.js"></script>
  <script src="/nicedit/nicEdit.js" type="text/javascript"></script>
  <script lang="javascript">

   bkLib.onDomLoaded(function() {
	  new nicEditor({fullPanel : true,iconsPath : '/nicedit/nicEditorIcons.gif'}).panelInstance('editor');
    new nicEditor({fullPanel : true,iconsPath : '/nicedit/nicEditorIcons.gif'}).panelInstance('introduce');
    });
    
    function updatebrandsort(id,sortid)
    {
       $.getJSON("/admin/updatebrandsort?id="+id+"&sortid="+sortid,function(result){
                               
       });
    }
 
	    $(document).ready(function(e) {
        $("#relate-icoimg").change(function(){
            var fd=new FormData();
            if($(this).get(0).files[0].size>4596640){
                $('#myfiletobigModal').modal('show');
                return false;
            }
            fd.append("upfile",$(this).get(0).files[0]);
            $("#progress-bar-show").show();
            $("#progress-bar-result").hide();
            $.ajax({
                url:"/imageapi/upload?action=uploadimage",
                type:"POST",
                processData: false,
                contentType:false,
                data: fd,
                dataType: "json",
                xhr: function() {  // custom xhr
                    myXhr = $.ajaxSettings.xhr();
                    if(myXhr.upload){ // check if upload property exists
                        myXhr.upload.addEventListener('progress',function(evt){
                            var percentComplete = Math.round(evt.loaded*100 / evt.total);
                            $( "#progress-bar").css("width",percentComplete*2);
                            $( "#progress-bar").html(percentComplete+'%');
                        }, false); // for handling the progress of the upload
                    }
                    return myXhr;
                },
                success:function(data){
                    if(data.state=="SUCCESS"){
                      $("#progress-bar-show").hide();
                      $("#progress-bar-result").show();
                      $("#icoimg").val(data.url);
                      $("#progress-bar-result").html("<a href='"+data.url+"' target=_blank><img height=\"50\" width=\"50\"  src=\""+data.url+"\"/></a>");
                      $('#myfilesuccessModal').modal('show');
                    }
                     
                }
            });
        });
    });	  
	
 
  </script>
</body>

</html>